#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    int sumOfLeftLeaves(TreeNode* root) {
        stack<TreeNode *> st;
        int sum = 0;
        if(root) st.push(root);
        while(!st.empty()){
            TreeNode * node = st.top();
            st.pop();

            if(node->right) st.push(node->right);
            if(node->left) {
                st.push(node->left);
                if(!node->left->left && !node->left->right)
                    sum += node->left->val;
            }
            
        }
        return sum;
    }
};